<?php
/**
 * Created by PhpStorm.
 * Author: QinShuai
 * Email: qinshuai0423@qq.com
 * Date: 2021/8/10
 */

namespace backend\controllers;

use common\models\Upload;
use Yii;
use yii\web\UploadedFile;

class UploadController extends BaseController
{
    public function actionIndex()
    {
        $model = new Upload();
        if (Yii::$app->request->isPost) {
            $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
            if (!$model->upload()) {
                return $this->error('上传失败');
            }
            $data = array_merge(Yii::$app->request->post(), ['url' => $model->basename,]);
            return $this->success($data, '上传成功');
        }

    }
}